package game.menu;

import game.utility.TextHandler;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

public class MenuElement {

	public static final int BACKGROUND_WIDTH = 300;
	public static final int BACKGROUND_HEIGHT = 40;
	public static final double TEXT_UPPER_MARGIN = 20;
	public static final double TEXT_LEFT_MARGIN = 20;
	public static final Color BACKGROUND_COLOR_ACTIVE = Color.lightGray;
	public static final Color BACKGROUND_COLOR_INACTIVE = Color.black;
	public static final Color FONT_COLOR_ACTIVE = Color.black;
	public static final Color FONT_COLOR_INACTIVE = Color.white;
	public static final int TEXT_SIZE = 20;
	public static final Font MENUFONT = new Font("Arial", Font.BOLD, 15);

	private Rectangle2D backGround;
	private String text;
	private String key;
	private boolean selected;

	public MenuElement(double xPos, double yPos, String key) {
		backGround = new Rectangle2D.Double(xPos, yPos, BACKGROUND_WIDTH, BACKGROUND_HEIGHT);
		this.key = key;
		this.text = TextHandler.singleton().getCommonText(key);
	}

	public void drawElement(Graphics2D g2d) {
		Font oldFont = g2d.getFont();
		g2d.setFont(MENUFONT);
		Color oldColor = g2d.getColor();

		if (selected) {
			g2d.setColor(BACKGROUND_COLOR_ACTIVE);
		} else {
			g2d.setColor(BACKGROUND_COLOR_INACTIVE);
		}
		g2d.fill(backGround);

		if (selected) {
			g2d.setColor(FONT_COLOR_ACTIVE);
		} else {
			g2d.setColor(FONT_COLOR_INACTIVE);
		}
		g2d.drawString(text, (float) (TEXT_LEFT_MARGIN + backGround.getX()), (float) (TEXT_UPPER_MARGIN + backGround.getY()));

		g2d.setFont(oldFont);
		g2d.setColor(oldColor);
	}

	public String getKey() {
		return key;
	}

	public double getMaxXPos() {
		return backGround.getMaxX();
	}

	public double getMaxYPos() {
		return backGround.getMaxY();
	}

	public double getXPos() {
		return backGround.getX();
	}

	public double getYPos() {
		return backGround.getY();
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}
}